﻿function webSocket() {
    if ("WebSocket" in window) {
        console.log("WebSocket Enable!");
        var Port = "86";
        while (Port == "") {
            Port = document.getElementById("UserPort").innerHTML.replace(/\s*/g, "")
        }
        var addr = getServerAddr();
        var ws = new WebSocket("ws://" + addr + ":" + Port + "/");
        ws.onopen = function () {
            console.log("WebSocket Opened!");
        }

        ws.onmessage = function (e) {
            if (g_bDrawFinish) {
                g_Receive = JSON.parse(e.data);
            }
        }
        ws.onclose = function (e) {
            console.log("close");
        }
        ws.onerror = function (e) {
            console.log("error");
        }
    } else {
        console.log("您的浏览器不支持WebSocket");
    }
}
